package com.guoshengdeu.door.util;

import lombok.Getter;
import lombok.Setter;

/**
 * <p>
 * 返回数据封装
 * </p>
 *
 * @author yfly
 * @since 2021-05-26
 */
@Getter
@Setter
public class RespResult<T> {
    private Integer code;
    private String msg;
    private T data;

    public RespResult() {
    }

    public RespResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public RespResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> RespResult success() {
        return success(null);
    }
    public static <T> RespResult success(T data) {
        return success(Result.success.msg, data);
    }
    public static <T> RespResult success(String msg, T data){
        return new RespResult(Result.success.code, msg, data);
    }
    public static RespResult error() {
        return error(Result.error.msg);
    }
    public static RespResult error(String msg){
        return error(Result.error.code, msg);
    }
    public static RespResult error(int code, String msg) {
        return new RespResult(code, msg);
    }
    public static RespResult nologin(){
        return new RespResult(Result.nologin.code, Result.nologin.msg);
    }

}

enum Result{
    success(1000, "请求成功"),
    error(1001, "请求错误"),
    nologin(1005, "用户未登录");
    protected final int code;
    protected final String msg;
    Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
}
